﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<!-- bootstrap css-->
<link href="web/listbox/css/bootstrap.min.css"  rel="stylesheet" 
media="screen">
<!-- bootstrap table css -->
<link rel="stylesheet" href="web/table/bootstrap-table.min.css" />

<link rel="stylesheet" href="web/combo/combo.select.css">

<!-- 设置该iframe中的背景色 与父页面一致-->
<style type="text/css" >
body { background:#f5f5f5  }
</style>
</head>
<body >
   
    
<div class="container">
  <div class="panel panel-primary">
    <div class="panel-heading">
          <h3 class="panel-title">
              药师资格审核 
          </h3>
   </div>
   
   
   <div class="panel-body">

    <div id="toolbar"> 
	
	<select id="user">
	<option value="-1">选择用户</option>
	<c:forEach var="u" items="${users }">
	<option value="${u.userId}">${u.userName }</option>
	</c:forEach>
	</select>
	<select class="form-control" id="patient">
	
	</select>
    </div>

    
    <table id="table"
           data-toolbar="#toolbar"
           data-id-field="id"
		   data-page-list="[10]"
		   data-show-refresh="true" 
           data-pagination="true" 
           data-response-handler="responseHandler"  
           >

    </table>

	</div>
 
 </div>





<!-- bootstrap js -->
<script src="web/vendors/jquery-1.9.1.min.js"></script>
<script src="web/listbox/js/bootstrap.min.js"></script>



<!-- bootstrap table js-->
<script src="web/table/bootstrap-table.min.js"></script>

<script src="web/combo/jquery.combo.select.js"></script>


<!-- layer  js-->
<script src="web/layer/layer.js"></script>

<script>
       $("#user").comboSelect();
	   $("#user").change(function(res){
		   $("#patient").attr("disabled",false);
		   $("#patient").html('');
		   if(res.currentTarget.value != -1){
			 $.get("admin/getAllPatient?userid="+res.currentTarget.value,function(res){
				    if(res.patients.length!=0) $("#patient").append("<option value='-1'>请选择</option>"); 
					
				    $(res.patients).each(function(i,o){
						$("#patient").append("<option value='"+o.id+"'>"+o.name+"</option>");
					});
					if(res.patients.length==0)
					{
						$("#patient").attr("disabled",true);
						$("#patient").append("<option value='-1'>暂无</option>");
					}
			 });  
		   }
	   });
	   
	   var $table = $('#table');
		 
	   window.operateEvents  = {

					'click .histRecord': function (e, value, row, index) {

						
						$(".histRecord").popover({
							trigger:'click'
							,
							content:row.histRecord
							,
							placement :'left'
						});
						
					}
  		  };
		 
	 $("#patient").on("change",function(res){
		   if(res.currentTarget.value != -1){
			   $('#table').bootstrapTable('refresh', {url:"admin/getTakeInfo?patientid="+ (res.currentTarget.value)});
			   }
	 });
	 
	 $('#table').bootstrapTable({
				columns: [	
				
				{
					field:'patientName',
					title:'患者',
					valign:'middle',
					align:'center'
				},
				{
					field: 'medicName',
					title: '药品名',
					valign:'middle',
					align:'center'
				}, {
					field: 'histDate',
					title: '服药日期',
					valign:'middle',
					align:'center'
				}, {
					field: 'histTime',
					title: '服药时间',
					valign:'middle',
					align:'center'
				} 
				,{
					field: 'histNum',
					title: '服药剂量',
					formatter:unitNameFormatter,
					valign:'middle',
					align:'center'
				},{
					field: 'histNumName', 
					valign:'middle',
					visible:false,
					align:'center'
				},{
					field: 'histStatus',
					title: '服药状态',
					formatter : statusFormatter,
					valign:'middle',
					align:'center'
				},{
					title:'服药心得',
					field: 'histRecord',
					valign:'middle',
					formatter : operateFormatter,
					events : operateEvents,
					align:'center',
				}
				],
				sidePagination: "server"
		});
	
         setTimeout(function () {
            $table.bootstrapTable('resetView');
         }, 200);
		 
		
	   	 function operateFormatter(value, row, index){
			
			var res = [];
			
			res.push(
				' <a class="histRecord" href="javascript:void(0)">'
            +'<i class="glyphicon glyphicon-credit-card"></i>' 
            +' </a>'
            ); 
			
			

            
    	 	return res.join('');
	  	 }
		function unitNameFormatter(value, row, index){
			

            
    	 	return value+'  '+row.histNumName;
	  	 }
		
	   	 function statusFormatter(value, row, index){
			var str="";
			if(value == 1){
				str="已服用";
			}else{
				str="未服用";
			}
            
    	 	return str;
	  	 }
		 

		


		 

		

		
		function getHeight() {
			return $(window).height() - $('h1').outerHeight(true);
		}
		
        $(window).resize(function () {
            $table.bootstrapTable('resetView', {
                height: getHeight()
            });
        });
	
		function responseHandler(res) {

			return res;
		}

	
		
		

</script>
</body>
</html>